﻿var IntialItems = function ($rightlist) {
    var str
    str = '<div id="dialog_activity1"><span>审批环节</span>'
    str += '<div class="item"><div class="topic">编号:</div><div class="topic"><input id="txtNum"  type="text" style="width:100px" /></div></div>'
    


    str += '<div class="item"><div class="topic">职责描述:</div><div class="topic"><input id="txtActDiscribe"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">环节名称:</div><div class="topic"><input id="txtActName"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">审批人:</div><div class="topic"><input id="txtActApprover" type="text" style="width:100px"/></div></div>'
    str += '<div class="item"><div class="topic">审批方式:</div><div class="topic"><select id="ddlApproveType" name="ddlApproveType"><option value="1">"审批权"</option><option value="2">"审核权"</option><option value="3">"知会权"</option><option value="4">"审核权/审批权"</option><option value="0">"--请选择--"</option></select></div></div>'
    str += '<div class="item"><div class="topic">审批类型:</div><div class="topic"><div id="radio"  ><input type="radio" class="radio" id="rdSerialTrue" name="radio" checked="checked"/><label for="rdSerialTrue">串签</label><input type="radio" class="radio" id="rdSerialFalse" name="radio"  /><label for="rdSerialFalse">并签</label></div></div>'
    
    str += '<div class="item"><div class="topic">标准时间:</div><div class="topic"><input id="txtTime"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">上一环节设置:</div><div class="topic"><input id="txtPre"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">审批人设置:</div><div class="topic"><input id="txtActSet"  type="text" style="width:100px" /></div></div>'


    str += '<button id="savebutton1" onclick="buttonclick1()">保存</button>'
    str += '</div>';
    $rightlist.append(str)
}
var IntialLines = function ($rightlist) {
    var str
    str = '<div id="dialog_activity2"><span>线属性编辑</span>'
    str += '<div class="item"><div class="topic">属性1:</div><div class="topic"><input id="task1"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">属性2:</div><div class="topic"><input id="task2" type="text" style="width:100px"/></div></div>'
    str += '<div class="item"><div class="topic">属性3:</div><div class="topic"><input id="task3" type="text" style="width:100px"/></div></div>'
    str += '<button id="savebutton2" onclick="buttonclick2()">保存</button>'
    str += '</div>'
    $rightlist.append(str)
}
var IntialStart = function ($rightlist) {
    var str
    str = '<div id="dialog_activity2"><span>初始条件编辑</span>'
    str += '<div class="item"><div class="topic">初始条件1:</div><div class="topic"><input id="task1"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">初始条件2:</div><div class="topic"><input id="task2" type="text" style="width:100px"/></div></div>'
    str += '<div class="item"><div class="topic">初始条件3:</div><div class="topic"><input id="task3" type="text" style="width:100px"/></div></div>'
    str += '<button id="savebutton2" onclick="buttonclick5()">保存</button>'
    str += '</div>'
    $rightlist.append(str)
}
var IntialEnd = function ($rightlist) {
    var str
    str = '<div id="dialog_activity2"><span>结论编辑</span>'
    str += '<div class="item"><div class="topic">结论1:</div><div class="topic"><input id="task1"  type="text" style="width:100px" /></div></div>'
    str += '<div class="item"><div class="topic">结论2:</div><div class="topic"><input id="task2" type="text" style="width:100px"/></div></div>'
    str += '<div class="item"><div class="topic">结论3:</div><div class="topic"><input id="task3" type="text" style="width:100px"/></div></div>'
    str += '<button id="savebutton2" onclick="buttonclick6()">保存</button>'
    str += '</div>'
    $rightlist.append(str)
}
var InitialDesignAttributebox = function ($designToolbox2) {
    $designToolbox2
    .append('<div id="divAttributeItems" class="pageEditorRightPanelBoxProperty"></div>')

}
var buttonclick4 = function () {
    
    $("#container").saveandloadFunction({ issaveorload: "load" })

}
var buttonclick3 = function () {
    $("#container").saveandloadFunction({ issaveorload: "save" })
    //window.location.reload();


}

var buttonclick5 = function () {
    var v = $("#container").getcurrent();
    v.addlistfunction({
        isitemorline: "start",
        
        state: "update"

    });
}
var buttonclick6 = function () {
    var v = $("#container").getcurrent();
    v.addlistfunction({
        isitemorline: "end",
        
        state: "update"

    });
}
var closemenu = function () {
    var h = $("#linemenu")
    h.css('display', 'none')
    document.oncontextmenu = ""
}
var changline = function () {
    var v = $("#container").getmoveingline();
    var start = v.start;
    var end = v.end;
    var $arrow = v.$arrow;
    if ($("#container").getstate() == "off") {
        $("#container").setonwrite();
        $arrow.finditemFunction(start, end);
        $arrow.arrowclick({ starget: start, etarget: end });
       
    }
}
var onrightclick = function (start, end, $arrow) {
    var h = $("#linemenu")

    document.oncontextmenu = function (e) {
        var $pageEditorMainBox = $(".pageEditorMainBox");
        var e = e || window.event;
        var x = e.x || document.body.scrollLeft + e.clientX;
        var y = e.y || document.body.scrollTop + e.clientY - $pageEditorMainBox[0].offsetTop;

        $("#container").setmoveingline(start, end, $arrow);
        h.css("width", 30)
        .css("height", 30)
        .css("left", x)
        .css("top", y)
        .css("background", "#8EC26F")
        .css('display', 'inline')
        .css("position", "absolute")

        document.oncontextmenu = closemenu;
        $("#container").click(function () {
            closemenu();
           
        })
        return false;


    }

}

var buttonclick2 = function () {
    var v = $("#container").getcurrent()


    var allthelines = $("#container").attrFunctions('l', "all");


    for (var i = 0; i < allthelines.length; i++) {
        var line = allthelines[i];
        var lineget = line.getlines()
        if (lineget.$startDiv[0] == v[0] || lineget.$endDiv[0] == v[0] || lineget.$middleDiv[0] == v[0]) {
            lineget.$startDiv.addlistfunction({
                isitemorline: "line",
                
                state: "update"

            });
            lineget.$endDiv.addlistfunction({
                isitemorline: "line",
                
                state: "update"

            });
            lineget.$middleDiv.addlistfunction({
                isitemorline: "line",
                
                state: "update"

            });
        }
    }

}
var buttonclick1 = function () {
    var v = $("#container").getcurrent();
    v.addlistfunction({
        isitemorline: "item",
        
        state: "update"

    });
}
var additemstate = function () {
    $("#container").find(".title,.contain1").each(
        function () {
            var $this = $(this);
            $this.click(
            function () {
                var $this = $(this);
                $("#container").setcurrent($this);
                classtargetFunction($this);
                //classtargetFunction("default", $($this[0].parentElement))
                $this.addlistfunction({
                    isitemorline: "item",

                    state: "read"
                });
            })
        })
}
var addlinstate = function () {
    $("#container").find(".line").each(
        function () {
            var $this = $(this)
            $this.click(
            function () {
                var $this = $(this)
                $("#container").setcurrent($this)
                var v = $this
                var allthelines = $("#container").attrFunctions('l', "all");
                for (var i = 0; i < allthelines.length; i++) {
                    var line = allthelines[i];
                    var lineget = line.getlines()
                    if (lineget.$startDiv[0] == v[0] || lineget.$endDiv[0] == v[0] || lineget.$middleDiv[0] == v[0]) {
                        classlineFunction(line);
                    }
                }
                $this.addlistfunction({
                    isitemorline: "line",

                    state: "read"
                });
            })
        })
}



var addstartorendstate = function () {
    $("#container").find(".content").each(
        function () {
            var $this = $(this)
            $this.click(
                function () {
                    var $this = $(this)
                    $("#container").setcurrent($this)
                    classtargetFunction($($this[0].parentElement))
                    if ($this[0].parentElement.children[0].className == "start") {
                           
                        $this.addlistfunction({
                            isitemorline: "start",
                                
                            state: "read"
                        });
                    } else {
                           
                        $this.addlistfunction({
                            isitemorline: "end",
                                
                            state: "read"
                        });
                    }
                        
                })
        })
}